package com.coolweather.android;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.coolweather.android.databinding.ActivityListBinding;

public class ListActivity extends AppCompatActivity {
    ActivityListBinding binding;

    private ListView listViewMembers;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= ActivityListBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Find views
        TextView textViewDormNumber = findViewById(R.id.textViewDormNumber);
        TextView textViewDormLeader = findViewById(R.id.textViewDormLeader);
        listViewMembers = findViewById(R.id.listViewMembers);

        // Set dormitory information (this should be replaced with actual data)
        textViewDormNumber.setText("寝室号：508");
        textViewDormLeader.setText("寝室长：黄科");

        // Initialize the ListView with member data
        String[] memberNames = new String[]{"黄科", "潘伟杰", "方孝先","徐睿"};
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
                R.layout.list_item_member,
                R.id.textViewMemberName,
                memberNames);
        listViewMembers.setAdapter(adapter);

        // Set up item click listener
        listViewMembers.setOnItemClickListener((parent, view, position, id) -> {
            String memberName = (String) parent.getItemAtPosition(position);
            Toast.makeText(ListActivity.this, memberName, Toast.LENGTH_SHORT).show();
        });
    }
}